package com.example.hdwx.myapplication.json.found_json;

import android.util.Log;

import com.example.hdwx.myapplication.eneity.found_eneitys.FoundTopicEneity;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * 发现话题区解析
 */


public class FoundTopicJSON {
    static String TAG="FoundTopicJSON";
public static List<FoundTopicEneity> getFoundCT(String response){
       List<FoundTopicEneity> dataCT = new ArrayList<>();
              try {
                     JSONObject object = new JSONObject(response);
                 for (int i = 1; i < 9; i++) {
                      JSONArray array = object.getJSONArray(i+"");
                            for (int j = 0; j < array.length(); j++) {
                       JSONObject object2 = array.getJSONObject(j);
                      FoundTopicEneity eneity = new FoundTopicEneity();
                       eneity.setLocationName(object2.optString("locationName"));
                       eneity.setLocationimage_url(object2.optString("image_url"));
                                eneity.save();
                                if(eneity.save()){
                                    Log.e(TAG,"FoundTopicJSON数据存储成功");
                                }else {
                                    Log.e(TAG,"FoundTopicJSON数据存储失败");
                                }
                                  //话题区加入集合
                                   dataCT.add(eneity);
                     }
                 }
                  return dataCT;
              } catch (JSONException e) {
                     e.printStackTrace();
              }
              return null;
       }
}
